package com.ruoyi.project.system.notices.controller;

import java.util.List;

import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.notices.domain.Notices;
import com.ruoyi.project.system.notices.service.INoticesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 通知管理Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@Controller
@RequestMapping("/system/notices")
@DataSource(value = DataSourceType.SLAVE )
public class NoticesController extends BaseController
{
    private String prefix = "system/notices";

    @Autowired
    private INoticesService noticesService;

    @RequiresPermissions("system:notices:view")
    @GetMapping()
    public String notices()
    {
        return prefix + "/notices";
    }

    /**
     * 查询通知管理列表
     */
    @RequiresPermissions("system:notices:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Notices notices)
    {
        startPage();
        List<Notices> list = noticesService.selectNoticesList(notices);
        return getDataTable(list);
    }

    /**
     * 导出通知管理列表
     */
    @RequiresPermissions("system:notices:export")
    @Log(title = "通知管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Notices notices)
    {
        List<Notices> list = noticesService.selectNoticesList(notices);
        ExcelUtil<Notices> util = new ExcelUtil<Notices>(Notices.class);
        return util.exportExcel(list, "通知管理数据");
    }

    /**
     * 新增通知管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存通知管理
     */
    @RequiresPermissions("system:notices:add")
    @Log(title = "通知管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Notices notices)
    {
        return toAjax(noticesService.insertNotices(notices));
    }

    /**
     * 修改通知管理
     */
    @RequiresPermissions("system:notices:edit")
    @GetMapping("/edit/{iid}")
    public String edit(@PathVariable("iid") Long iid, ModelMap mmap)
    {
        Notices notices = noticesService.selectNoticesByIid(iid);
        mmap.put("notices", notices);
        return prefix + "/edit";
    }

    /**
     * 修改保存通知管理
     */
    @RequiresPermissions("system:notices:edit")
    @Log(title = "通知管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Notices notices)
    {
        return toAjax(noticesService.updateNotices(notices));
    }

    /**
     * 删除通知管理
     */
    @RequiresPermissions("system:notices:remove")
    @Log(title = "通知管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(noticesService.deleteNoticesByIids(ids));
    }
}
